home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / T / THINK C 5.0.3 Update.cpt / THINK C 5.0.3 Update / About THINK C 5.0.3 next >
Text File  |  1992-09-03  |  31KB  |  788 lines

  1. ABOUT THINK C 5.0.3
  2. ===================
  3. Copyright © 1992 Symantec Corporation. All rights reserved.
  4. September 2, 1992
  5. Font: Geneva 12
  6.  
  7. INTRODUCTION
  8. =============
  9. THINK C 5.0.3 corrects some problems with debugging programs on a 
  10. Macintosh Quadra and corrects some other problems in THINK C 5.0.
  11. THINK C 5.0.3 contains fixes included in 5.0.1 and 5.0.2.   The converter
  12. program can convert THINK C 5.0, 5.01., and 5.0.2 to THINK C 5.0.3.
  13.  
  14. The THINK Class Library 1.1.2 update is also available. It describes some 
  15. features of the THINK Class Library that weren’t included in the  the 
  16. “Object-Oriented Programming” manual, and fixes some bugs. It is the 
  17. same update that was available with THINK C 5.0.2. You should be able to
  18. find the THINK Class Library update in the same place you found the
  19. THINK C 5.0.3 update. 
  20.  
  21. This document has five more sections:
  22.  
  23.     •  UPDATING THINK C tells you how to run “THINK C -> 5.0.3” to 
  24.         update your copy of THINK C.
  25.  
  26.     •  WHAT THIS UPDATE FIXES lists the most important bugs that 
  27.         this update fixes.  Bugs that were not addressed in earlier 
  28.         versions (THINK C 5.0.1 and THINK C 5.0.2) are marked with 
  29.         double bullets "••".
  30.         
  31.     •  LAST MINUTE CHANGES lists some last minute changes and 
  32.         corrections to the THINK C User Manual and Standard Libraries
  33.         Reference. This section contains much of the information in the 
  34.         READ ME file on your THINK C 5.0 disk, in addition to some more  
  35.         recent information. 
  36.  
  37.     •  WORK-AROUNDS describes how to avoid some problems you might 
  38.         have in using THINK C 5.0.3.
  39.  
  40.     •  TECH TIPS answers some common questions that people ask  
  41.         our Technical Support staff. When you have a problem with 
  42.         THINK C, use this section along with Appendix B, 
  43.         “Troubleshooting,” to try to find a solution. And when you 
  44.         port a program from THINK C 4.0 to THINK C 5.0, use this 
  45.         section along with Appendix A, “What’s New,” for some helpful 
  46.         hints.  
  47.   
  48.     •••••••••
  49.     IMPORTANT
  50.     •••••••••
  51.         Some copies of the Object-Oriented Programming Manual have 
  52.         a misprint: page 313 is a duplicate of page 321. To get a copy of
  53.         the correct 313, you need to use the THINK Class Library 1.1.2 
  54.         update.
  55.  
  56. UPDATING THINK C
  57. =================
  58. This update transforms your existing THINK C 5.0 application to THINK C 
  59. 5.0.3. You will run the patch program “THINK C -> 5.0.3” and then replace
  60. your debugger, oConv program, oops.h, and member.c file.
  61.  
  62.     •••••••••
  63.     IMPORTANT
  64.     •••••••••
  65.         The partition size for THINK C -> 5.0.3 is set to 1 Mb (megabyte). 
  66.         If you have only 1 Mb of RAM, you’ll need to set the partition size 
  67.         to 650K. In the Finder, select the THINK C -> 5.0.3 application, 
  68.         choose Get Info…, and edit the Current Size field in the Get 
  69.         Info… dialog. If you set the partition below 650K, the application
  70.         may quit with error ID = -108.  If you see this message, your 
  71.         THINK C application isn’t damaged, and you can run the update 
  72.         program again with a larger partition.
  73.  
  74.     1. Make sure that you have your original THINK C application.
  75.         You won't need it for this update, but you should make
  76.         sure that you have a backup in case the update fails. Do not
  77.         patch your original master disk.
  78.  
  79.     2. Double-click on the patch program “THINK C -> 5.0.3” to
  80.         launch it. Click on the Update THINK C button to continue.
  81.  
  82.     3. Find your existing copy of THINK C in your THINK C Folder.
  83.         Select it and click on the Patch button.
  84.  
  85.     4. If the patch was successful, you'll get a confirmation.
  86.     
  87.     5. Replace these files with the copies included with the update.
  88.         √ THINK C Debugger 5.0. It should be in your “THINK C 5.0” folder.
  89.         √ oConv. It should be in the “THINK C 5.0 Utilities” folder in your
  90.            “Development” folder.
  91.         √ oops.h. It should be in the “oops Libraries” folder in your 
  92.            “THINK C 5.0 Folder”.
  93.         √ member.c. It should be in the “sources” folder in the 
  94.            “oops Libraries” folder in the “THINK C 5.0 Folder”.
  95.  
  96.     6. Recompile all the files in your projects to make sure they
  97.         take advantage of the changes. To recompile a project, open 
  98.         it in THINK C, choose Remove Objects from the Project menu, 
  99.         and choose Bring Up To Date from the Project menu.
  100.  
  101. WHAT THIS UPDATE FIXES
  102. =======================
  103. THINK C 5.0.3 corrects some problems with debugging programs on a 
  104. Macintosh Quadra and corrects some other problems in THINK C 5.0. 
  105. This section describes the most significant bugs that THINK C 5.0.3 fixes. 
  106. It contains these parts:
  107.  
  108. •  “The Environment” describes what’s fixed in the THINK C 
  109.     environment.
  110. •  “The Debugger” describes what’s fixed in the THINK C Debugger.
  111. •  “Optimizations” describes what’s fixed in THINK C’s global optimizer and
  112.      other optimizations.
  113. •  “Object-Oriented Programming Extensions” describes what’s fixed in 
  114.     THINK C’s object-oriented programming extensions.
  115. •  “Compiler and Linker” describes what else is fixed in THINK C’s compiler 
  116.     and linker.
  117. •  “oConv” describes a fix to the .o converter program.
  118.  
  119. The Environment
  120. ---------------
  121. •• THINK C handles files whose names begin with a period (.) more 
  122.      reliably.
  123.  
  124. •• When editing files with many markers, the editor is now faster and
  125.      more reliable.
  126.  
  127. •• Windows now zoom correctly on multi-monitor systems.
  128.  
  129. •• The Browser window now closes correctly.
  130.  
  131. •• Choosing Full Titles now always correctly updates window titles.
  132.  
  133. •• THINK C contains hooks that let third party developers write extensions
  134.      to the editor.
  135.  
  136. •  When you’re running System 7.0 in 32-bit addressing mode, these features
  137.     now work correctly:
  138.         √ The “Grep” option in the Find… dialog.
  139.         √ Using the Browser to look up a method or class definition.    
  140.         
  141. •  Some utilities that add features to the THINK C 5.0 editor will not 
  142.     work with THINK C 5.0.3. Contact the author of the utility for a new 
  143.     version.
  144.  
  145. •  The Get Info… dialog doesn’t truncate the last character of the JUMP table
  146.     size.
  147.  
  148. •  In the Options… dialog, the Copy button now works correctly.
  149.  
  150. •  In the Set Project Type… dialog, five-digit numbers now fit in the 
  151.     Partition field. Also, the dialog will not let you enter values greater
  152.     than 32767 in the Partition field. 
  153.  
  154. •  The Size Flags menu in Set Project Type… dialog  contains a new option: 
  155.     Use TextEdit Services. Set this bit if your application lets the user use 
  156.     inline input to enter text in a script system that uses ideographs.
  157.  
  158. • The Browser does not combine the method lists for classes that have 
  159.    similar names. Also, it no longer places method menus off the screen on 
  160.    some monitors.
  161.  
  162. The Debugger
  163. ------------
  164. •• Single stepping works reliably in functions that contain unreachable 
  165.      code.
  166.  
  167. •• Changing the value of a double variable in a Data window always         
  168.      works now.
  169.  
  170. •• Using balloon help in the debugger no longer crashes.
  171.  
  172. •• Choosing Clear All does not reorder windows.
  173.  
  174. •  The debugger works correctly on a Macintosh Quadra.
  175.  
  176. •  In a Data window, you can enter a value greater than 0x7FFFFFFF for a
  177.     integer.
  178.  
  179. •  You will not crash the debugger by selecting Go soon after it’s launched.
  180.  
  181. Optimizations
  182. -------------
  183. •• The “Code motion” option is now more effective.
  184.  
  185. •  The “Suppress redundant loads” option is more careful when choosing to
  186.     suppress a load.
  187.  
  188. •  The “CSE elimination” option is more careful when deciding
  189.     whether to eliminate common sub-expressions in a conditional
  190.     statement.
  191.     
  192. •  The “Induction variable elimination” option is more careful when 
  193.     deciding whether an expresion is an induction variable.
  194.     
  195. •  The “CSE elimination” and “Register coloring” options are more careful 
  196.     when optimizing statements with the operators && or ||.
  197.  
  198. •  The nooptimize pragma directive disables more optimizations. In addition 
  199.     to disabling the global optimizer, it also turns off automatic register 
  200.     assignment. For more information on the nooptimize pragma directive, 
  201.     see “The pragma nooptimize directive” on page 195 in THINK C User
  202.     Manual.
  203.  
  204. Object-Oriented Programming Extensions
  205. -------------------------------------
  206. •• You can use a precompiled header with object-oriented programming
  207.      extensions in a program that doesn’t use those extensions.
  208.  
  209. •• The member() function now works correctly with 4-byte integers when 
  210.      the “Far Data” and “Far Code” options are  off.
  211.  
  212. •  THINK C now flags as an error a static member function that references
  213.     a non-static member of a class without an object pointer.
  214.     
  215. •  Calling a virtual static method works correctly.
  216.  
  217. Compiler and Linker
  218. ------------------
  219. •• In a code resource, a call to a function in another segment will work,
  220.      even if the user turns on the “32-bit Addressing” mode while the
  221.      resource is executing.
  222.  
  223. •• THINK C can handle more complex expressions and displays the
  224.      “expression too complex” error message less often.
  225.  
  226. •• THINK C always treats identical arrays types as identical now.
  227.  
  228. •• The inline assembler correctly generates offsets for expressions
  229.      involving an array field of a struct, such as OMSPacket.data[1](a2).
  230.  
  231. •• When building an application, THINK C generates now an error message 
  232.      when you use an illegal pc-relative reference. Previously, it ignored
  233.      the error.
  234.  
  235. •  There is now a limit of 256 segments per project. Previously, there was
  236.     a limit of 128 segments per project.
  237.     
  238. •  You do not get the incorrect error message “internal error: Bad ZREF,” if 
  239.     the linker encounters an error while building your program. 
  240.  
  241. •  Using the Separate STRS option does not crash THINK C.
  242.  
  243. •  In a link map, offsets for all entry points in the main segment are 
  244.     correct.
  245.      
  246. •  If you use typedef to define a type as void and declare something with 
  247.     that type, you do not get the error message “illegal use of void”.
  248.     
  249. •  If there are several #define statements before a precompiled header, 
  250.     THINK C does not generate an internal compiler error. 
  251.     
  252. •  THINK C now generates an error message if you try to precompile a 
  253.     header that #defines something before #include’ing a precompiled
  254.     header.
  255.  
  256. •  THINK C now correctly stores the size of array types declared in
  257.     precompiled headers. 
  258.  
  259. •  If a macro and a type have the same name, and you use the name to 
  260.     declare a variable, THINK C does not give you the incorrect error message 
  261.     “invalid declaration.”     
  262.  
  263. •  A multi-segment code resource, driver, or desk accessory built with 
  264.     THINK C works correctly if it is unlocked and moves in memory.
  265.     
  266. •  When assigning one struct to another, the code THINK C generates now
  267.     works correctly if the source struct is cached in an MC68040 data
  268.     register.
  269.  
  270. •  The FNEG.X instruction generates correct code when you use it with a 
  271.     single floating-point register argument. Previously, for example,   
  272.     “FNEG.X FP0” generated code for “FABS.X FP0”.
  273.  
  274. oConv
  275. -----
  276. •  Libraries produced with oConv 1.0.6 no longer require an extra 
  277.     conversion step to be used in THINK C 5.0 projects.
  278.  
  279.  
  280. LAST MINUTE CHANGES
  281. ====================
  282. This section lists some last minute changes and corrections to the THINK C 
  283. User Manual and Standard Libraries Reference. It contains much of the 
  284. information in the READ ME file on your THINK C 5.0 disk, in addition to some 
  285. more recent information.
  286.  
  287. Welcome
  288. --------
  289. • If you have only one megabyte of RAM, you cannot compile projects that
  290.    use MacHeaders. Instead, try to create a smaller precompiled header
  291.    that includes only those header files you need. For more information, see
  292.    “Editing the MacHeaders file” on page 165. You can compile projects that 
  293.    use the ANSI library with one megabyte.
  294.          
  295. Installing THINK C 5.0
  296. --------------------
  297. • On page 20, step 4 should refer you to Figure 2-2, not 2-1.
  298.  
  299. • On page 21, the folder is shown in Figure 2-3, not 2-1.
  300.  
  301. Tutorial: Hello World
  302. -------------------
  303. •  On page 34, the error message in Figure 3-7 is incorrect and should
  304.     be “can’t open file ‘stdio.h’.” And in the first complete sentence on page 
  305.     35, the folder THINK C can’t find is the C Libraries folder.
  306.  
  307. Tutorial: MiniEdit
  308. ----------------
  309. •  The first paragraph on page 49 tells you to click the wrong button. You
  310.     should click on the Done button, not the Cancel button.
  311.  
  312. •  On pages 55 and 56, the Set Project Type… dialog in Figures 4-14 and 
  313.     4-15 probably doesn’t match yours. The default value for the SIZE Flags
  314.     field is 0000, and not 0800. The project works correctly with either 
  315.     value.
  316.     
  317. •  On page 57,  the first sentence of the section “Using a Resource File” is
  318.     incorrect. You didn’t copy the MiniEdit Folder from disk THINK C 4. 
  319.     Instead you installed it with the self-extracting archive “THINK C 5.0 
  320.     Demos.sea,” according to the instructions in Chapter 2, “Installing 
  321.     THINK C 5.0.”
  322.     
  323. Tutorial: Bullseye
  324. -----------------
  325. •  On page 68, Figure 5-11 shows a hollow arrow pointing at DrawBullseye().
  326.     If you follow the instructions up to here, you’ll actually see a solid
  327.     arrow pointing at EndUpdate().
  328.  
  329. The Project
  330. -----------
  331. •  In THINK C 5.0.3, the Size Flags menu in Set Project Type… dialog  
  332.     contains a new option: Use TextEdit Services. Set this bit if your 
  333.     application lets the user use inline input to enter text in a script 
  334.     system that uses ideographs.
  335.     
  336. Files & Folder
  337. -------------
  338. •  There are some restrictions on once-only headers (#pragma once). 
  339.     √  #Pragma once is case sensitive. For example, if you include a file once 
  340.         with the statement “#include <stdio.h>” and later with the statement
  341.         “#include <StdIO.h>”, THINK C will include it twice.
  342.     √  #Pragma once doesn’t distinguish between files included with <...> 
  343.          and "...". For example, say you have two header files named xyz.h, one 
  344.          in the THINK C tree and one in the project tree. If you include one with 
  345.          “#include <xyz.h>” and another with “#include "xyz.h"”, THINK C will
  346.          not include the second file.
  347.     
  348. The Compiler
  349. -------------
  350. •  The THINK C compiler and optimizer use MultiFinder memory. If you get an
  351.     “Out of Memory” error, quit your other running applications to increase 
  352.     the amount of MultiFinder memory available.
  353.  
  354. •  The optimizer can take a long time to optimize extremely large and 
  355.     complex functions (typically, more than 10 pages of dense code).
  356.  
  357.  •  In THINK C 5.0.3, the nooptimize pragma directive does more. In addition 
  358.      to disabling the global optimizer, it also turns off automatic register 
  359.      assignment and honors register declarations. For more information on 
  360.      the nooptimize pragma directive, see “The pragma nooptimize directive” 
  361.      on page 195.
  362.      
  363. •  In THINK C 5.0.3, there are two new options for the options pragma
  364.     directive. You cannot change these options within a function. For more 
  365.     information on the options pragma directive, see page “Accessing Option 
  366.     Settings in You Code” on page 195.
  367.  
  368.     √ class_names: If this option is off, THINK C does not generate class 
  369.         names in the runtime data structures for classes and you cannot use 
  370.         the new_by_name() or class_name() functions. Turning this option 
  371.         off can significantly reduce the size of your global data if you 
  372.         use very long class names.
  373.     
  374.     √ align_arrays: You can use this to defeat the alignment of even-length 
  375.         char arrays within structs. For example,
  376.     
  377.             struct S {
  378.                 char f1;
  379.                 char f2[7];
  380.                 char f3;
  381.                 char f4[8];
  382.                 char f5;
  383.             };
  384.     
  385.         Normally, THINK C allocates the member f4 on an even boundary and 
  386.         inserts a pad byte between f3 and f4. The entire struct occupies
  387.         20 bytes. If the align_arrays option is off, THINK C allocates f4 on an
  388.         odd boundary and doesn’t insert a pad character. The struct occupies
  389.         only 18 bytes.
  390.  
  391. The Assembler
  392. --------------
  393. •  The note on page 270 needs some explanation. When you write a 
  394.     function with in-line assembly and you declare that function pascal,  you 
  395.     need to return the function’s value in a return statement outside the 
  396.     assembly block. Don’t put the return value into D0 yourself. For example, 
  397.     use this:
  398.     
  399.             pascal int foo (void)
  400.             {
  401.                 asm {
  402.                     . . .
  403.                 }
  404.                 return 1;
  405.              }
  406.         
  407.     instead of this:
  408.     
  409.             pascal int foo (void)
  410.             {
  411.                 asm {
  412.                     . . .
  413.                     move.w     #1, D0
  414.                 }
  415.              }
  416.  
  417.     Also note that you cannot return a value from an assembly block.
  418.     In an assembly block, you can use a return statement only if it does not 
  419.     return a value. For example, this code fragment causes an error: 
  420.     
  421.             pascal int foo (void)
  422.             {
  423.                 asm {
  424.                     . . .
  425.                     return 1    // NO! Cannot return a value from
  426.                 }                   // within an asm block
  427.              }    
  428.                  
  429. •  In THINK C 5.0, you need to write multi-line assembly language macros
  430.     differently than with earlier versions of THINK C. For example, this
  431.     multi-line macro causes an error in THINK C 5.0:
  432.  
  433.         #define LongMult(r, s1, s2) \
  434.             asm {  \
  435.                 move.w  s1, d0  \
  436.                 muls  s2, d0  \
  437.                 move.l  d0, r \
  438.             }
  439.  
  440.         void foo(void)
  441.         {
  442.             int a, b;
  443.             long d;
  444.  
  445.             LongMult(d, a, b)    // Syntax error
  446.             . . .
  447.         }
  448.  
  449.     Multi-line assembler macros cause errors because the THINK C 5.0
  450.     preprocessor expands the macro as one long line, like this:
  451.  
  452.         asm { move.w s1, d0  muls s2, do  move.l d0,r }
  453.  
  454.     The inline assembler doesn’t recognize the expansion as valid assembly
  455.     language. You can define the macro like this:
  456.  
  457.         #define LongMult(r, s1, s2) \
  458.             asm { move.w  s1, d0 } \
  459.             asm { muls  s2, d0  } \
  460.             asm { move.l  d0, r } 
  461.  
  462.     Or you can define LongMult as just the assembly language statements, 
  463.     without enclosing them in asm { . . . }, like this:
  464.  
  465.         #define LongMult(r, s1, s2) \
  466.             move.w  s1, d0  \
  467.             muls  s2, d0  \
  468.             move.l  d0, r 
  469.  
  470.     And then use the macro like this:
  471.  
  472.         void foo(void)
  473.         {
  474.             int a, b;
  475.             long d;
  476.  
  477.             asm {
  478.                 LongMult(d, a, b) 
  479.             }
  480.         . . .
  481.         }
  482.  
  483. •  On page 267, there’s an error in the section “C function entry.” It 
  484.     incorrectly states how THINK C handles a char-sized argument. The last 
  485.     two paragraphs in that section should read:
  486.     
  487.         All arguments occupy an even number of bytes on the stack.
  488.         If there is no prototype for a char-sized argument, it is placed 
  489.         in the low byte of an int, which may be 2 or 4 bytes, depending
  490.         on your option settings.
  491.         
  492.         If there is a prototype for a char-sized argument, it is placed
  493.         in the high byte of a short.
  494.         
  495. •  On page 270, Figure 13-3 is incorrect. The positions of arg-1 and arg-N
  496.     should be reversed, like this:
  497.  
  498.                -------------------------------
  499.                  Space for return value (if any)
  500.                -------------------------------
  501.                  arg-1
  502.                -------------------------------
  503.                  . . .
  504.                -------------------------------
  505.                  arg-N
  506.                -------------------------------
  507.        SP->   return address
  508.                -------------------------------
  509.                
  510.     The text above Figure 13-3 is correct.
  511.            
  512. The Debugger
  513. ------------
  514. •  To stop the debugger from saving the current session, hold down the 
  515.     Option key as you exit the debugger.
  516.  
  517. •  To make the debugger display the source and data window in their
  518.     default positions, hold down the Shift key as you enter the debugger.
  519.  
  520. •  To stop the debugger from restoring saved breakpoints and data 
  521.     expressions hold down the Option key as you enter the debugger.
  522.     
  523. •  Do not step into Macintosh Toolbox routines OpenPicture(), Open Poly(),
  524.     OpenRgn(). Your machine could crash.
  525.     
  526. The Profiler
  527. -----------
  528. •  The instructions in the last paragraph of  “Changing which timer to use” 
  529.     on page 285 are incorrect. They should read:
  530.  
  531.         To create a profile library that uses the tick counter, follow 
  532.         these steps:
  533.         1.  In the Finder, create a new copy of the profile project and 
  534.              give it a new name, like tick profile.
  535.         2.  Open the new project with THINK C.
  536.         3.  Choose Options… from the Edit menu.
  537.         4.  Select Prefix from the pop-up menu in the Options…  dialog.
  538.         5.  Comment out the line that defines _VIATIMER_. It should 
  539.              look like this: “/*  #define _VIATIMER_  */”.
  540.         6.  Click OK.
  541.         7.  Choose the Compile command to recompile the file.
  542.  
  543. oConv
  544. ------
  545. • oConv can convert most reference records, despite what it says in the
  546.    section “Conversion Limits” on page 294. It can convert most records 
  547.    from high-level languages and many from assembly language. Here are
  548.    some types of references it cannot convert:
  549.    √  32-bit relative references generated by the -m switch in the MPW C 
  550.         compiler
  551.    √  32-bit relative references from assembly language
  552.    √  16-bit data-to-code or data-to-data references in assembly language.
  553.  
  554.    oConv can convert the reference records created by the examples on 
  555.    page 294.
  556.    
  557. •  In the section “Converting Large .o Files,” the dumpobj command line on
  558.     page 292 is incorrect. It should read:
  559.  
  560.         dumpobj OFILE.o -d -h -i -n > OLIST.txt 
  561.     
  562.     And before you execute the replace command, the file OLIST.txt must be
  563.     in an MPW window.
  564.  
  565. Standard Libraries Reference
  566. --------------------------
  567. •  In the example for free() on page 181, the typedef should be
  568.  
  569.         typedef struct {
  570.             int a, b;
  571.         } Foo, *FooPtr;
  572.  
  573.  
  574. •  On pages 208 and 209, the return value for the “isxxxx” family of 
  575.     functions (isalnum(), isalpha(), etc.) is wrong.  The second sentence in
  576.     the second paragraph should read:
  577.  
  578.         It returns non-zero if c is a member of the category,  and 
  579.         0 (zero) value if c isn’t.
  580.         
  581.     And the table in the section “Returns” should read:
  582.     
  583.         If c is…                           The function returns…
  584.         in the category               non-zero
  585.         not in the category         0 (zero)
  586.         
  587. •  The example for printf() on page 238 should be
  588.  
  589.         #include <stdio.h>
  590.         
  591.         main()
  592.         {
  593.             printf ( "pi = %7.5f", 3.141593 );
  594.         }
  595.  
  596.  
  597. WORK-AROUNDS
  598. ===============
  599. This section describes how to avoid known problems in THINK C 5.0.3.
  600.  
  601. •• THINK C may produce incorrect code when an array subscript contains
  602.      an arithmetic expression with large numbers. Assign the 
  603.      expression to a temporary variable and use the temporary variable
  604.      as the subscript. For example:
  605.      
  606.           char globalArray;
  607.           char array[30000];
  608.           
  609.           foo()
  610.           {
  611.                int i=25000;
  612.                int j;
  613.                char c;
  614.                
  615.           // This may fail depending on global data configuration
  616.                c=globalArray[i-24000];
  617.                
  618.           // This will always work.
  619.                j=i-24000;
  620.                c=globalArray[j];
  621.           }
  622.  
  623. •• CMaster version 1.0.8 or earlier does not work with THINK C 5.0.3. If 
  624.      you’re comfortable with using ResEdit or Resourcerer to edit resources, 
  625.      you can edit CMaster and change the 'GLOB' 10000 resource to 
  626.      hex 0000475A and 'GLOB' 10001 to hex 000045A4. Otherwise, you can 
  627.      send your original CMaster disk to Jersey Scientific for an upgrade to 
  628.      1.0.9, or download a CMaster upgrade program from CompuServe or the 
  629.      Internet site sumex.stanford.edu.
  630.      
  631.  
  632. TECH TIPS
  633. =========
  634. THINK C has many new features and enhancements that help you improve
  635. your code.  Two changes in  THINK C 5.0 affect existing programs and 
  636. programs that you write in the future. The first change is that THINK C 5.0 
  637. conforms the ANSI standard. The second change is that THINK C now uses 
  638. the same Macintosh Toolbox interface files that Apple provides, and these 
  639. files contain more type-checking information than the built-in interfaces 
  640. in earlier versions of THINK C.
  641.  
  642. Though these changes in the THINK C development environment may mean 
  643. some changes to your existing programs, these programs will be easier to 
  644. maintain and more bug-free.
  645.  
  646. MacHeaders uses Apple’s interfaces
  647. --------------------------------
  648. The MacHeaders file that comes with THINK C 5.0 contains the interfaces for 
  649. the most common Macintosh Toolbox routines. This MacHeaders file is 
  650. precompiled with the "Check pointer types" option off, so all pointer types 
  651. in function prototypes are treated as generic pointers of type void *. If you 
  652. want stricter type checking for Macintosh Toolbox routines, follow the 
  653. instructions in Mac #includes.c to turn the stricter checking on.
  654.  
  655. Using stricter type-checking means that you need to cast parameters to 
  656. all Macintosh Toolbox routines, even the common ones like HLock() and 
  657. HUnlock(). The additional work pays off when THINK C catches an attempt to 
  658. pass a variable of the wrong type to a Toolbox routine.
  659.  
  660. Prototype Helper helps convert programs
  661. -------------------------------------
  662. The THINK C 5.0 package includes a tool called Prototype Helper to help you 
  663. convert your programs to the new ANSI standard. Prototype Helper creates 
  664. extra header files that contain the prototypes for all the functions in your 
  665. program files. Prototype Helper also converts old-style function definitions 
  666. to new-style ANSI function definitions. Many programmers report that 
  667. Prototype Helper helped them discover subtle problems that have hidden in 
  668. programs for months.
  669.  
  670. Prototype Helper uses a heuristic to convert your files, and may not always
  671. do what you expect. Since it alters your files in place, be sure to keep a
  672. backup of your files until you’re confident your converted files work 
  673. properly.
  674.  
  675. Function pointer types are more strictly enforced
  676. ---------------------------------------------
  677. THINK C 5.0 is much stricter about function pointer types than earlier 
  678. versions of THINK C.  In older versions, THINK C ignored the parameters to a 
  679. function pointer. For example, THINK C 4.0 treated both of these types 
  680. identically:
  681.  
  682.     typedef int (*SomeProcPtr)();
  683.     typedef int (*OtherProcPtr)(char);
  684.  
  685. THINK C 5.0 treats these two declarations as distinct types. It distinguishes 
  686. function pointer types by parameters as well as return value. THINK C 5.0 
  687. also allows the use of the keyword pascal as part of the function pointer 
  688. type. 
  689.  
  690. This change affects programs that use the type ProcPtr as a generic pointer. 
  691. For example, in THINK C 4.0, you could write this:
  692.  
  693.     ProcPtr fp;
  694.     (*fp)(1, 2L, 3);
  695.  
  696. In THINK C 5.0, this function pointer needs an explicit type. You can cast it 
  697. like this:
  698.  
  699.     ((void (*)(short, long, short)) fp) (1, 2L, 3);
  700.  
  701. Or, even better, you can define a type first:
  702.  
  703.     typedef void (*ShortLongShortFnPtr)(short, long, short);
  704.  
  705.     ShortLongShortFnPtr fp;
  706.  
  707.     fp(1, 2L, 3);
  708.     
  709. Note that the function pointer does not need to be dereferenced to perform 
  710. the call. The compiler does that for you.
  711.  
  712. short * and int * are not the same type
  713. -----------------------------------
  714. By default, the type short and the type int are the same size: 16 bits. 
  715. However, they are not the same type. The difference is particularly apparent 
  716. in functions that take pointers to shorts and pointers to int. For example:
  717.  
  718.     void f(short *p)
  719.     {
  720.        ...
  721.     }
  722.  
  723.     void g(void)
  724.     {
  725.        int j;
  726.  
  727.        f(&j);  // ERROR: types are incompatible
  728.        f((short *)&j);  // OK
  729.      }
  730.  
  731. Note that none of the Macintosh Toolbox routines take ints as parameters. 
  732. They take either shorts or longs.
  733.  
  734. _fp1() and _elems1() are internal SANE routines
  735. -------------------------------------------
  736. If you get an error message about a function called _fp1() or _elems1(), 
  737. don't panic. These are the compiler's name for the SANE routines that 
  738. implement the high-level SANE call on the highlighted line. You may get this 
  739. error if you're using SANE, and if you try and pass a variable of type double 
  740. to a SANE routine that expects an extended. For example, the sqrt() function 
  741. below expects its argument to be of type extended.
  742.  
  743.     #include <SANE.h>
  744.     ...
  745.     extended x;
  746.     x = sqrt((double) 123 / 4);
  747.  
  748. To see exactly how the _fp() function is called, use the Preprocess command 
  749. in the Source menu.
  750.  
  751. Even-sized arrays are now even-word aligned
  752. -----------------------------------------
  753. In some cases, THINK C 5.0 packs binary data differently than earlier 
  754. versions. If you have a structure that describes the format of binary data,  
  755. check whether the fields match up correctly in the new version. THINK C 5.0 
  756. aligns even-length arrays on even word boundaries and introduces a pad byte 
  757. if necessary. For example, in THINK C 4.0 this structure would be 12 bytes 
  758. long:
  759.  
  760.     struct foo {
  761.         char x;
  762.         char y[10];
  763.         char z;
  764.     };
  765.  
  766. The compiler would place the field y immediately after the field x. So y ends 
  767. up on an odd word boundary.
  768.  
  769. In THINK C 5.0, the same structure takes up 14 bytes. In order to align the 
  770. field y, the compiler places a pad byte between x and y. At this point, the 
  771. field z is placed at an odd address, making the structure's length 13 bytes. 
  772. Both THINK C 4.0 and THINK C 5.0 compilers will make sure that a structure 
  773. is an even length, so it is padded out with one more byte at the end.
  774.  
  775. To make sure that the structure is the same size in THINK C 5.0, make the 
  776. array odd-sized, and add the last element of the array as a field just after 
  777. the array. Since THINK C doesn't enforce array bounds checking, you can use 
  778. this declaration the same way as you used the previous one:
  779.  
  780.     struct foo {
  781.         char x;
  782.         char y[9];
  783.         char y10;     // introduce dummy name
  784.         char z;
  785.     };
  786.  
  787. To get the old behavior, turn off the align_arrays pragma directive 
  788. described earlier in this document.